//
//  PerCenterViewController.m
//  CYWFrame
//
//  Created by Macx on 2017/7/21.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "PerCenterViewController.h"

//#import "PerRealNameViewController.h"
#import "SDWebImage/UIButton+WebCache.h"
#import "LCButton.h"
#import "RealNameContentViewController.h"
#import "LoginViewController.h"
#import "PerSettingViewController.h"
#import "PerTableViewCell.h"
#import "MessageViewController.h"
#import "PerInfoEditViewController.h"
#import "PerFocusAFansViewController.h"
#import "MallOrderManageViewController.h"
#import "MKJShoppingCartViewController.h"
#import "PerWalletViewController.h"
#import "PerWalletRecordViewController.h"
#import "BindingPhoneViewController.h"
#import "FansRankViewController.h"
#import "MallShopCartViewController.h"
#import "MallAddressViewController.h"
#import "WebViewWithStringVC.h"
#import "MallCollectViewController.h"
#import "PerWalletNewViewController.h"
#import "MyResumeManageViewController.h"
#import "MyBuyTogetherTableViewCell.h"
#import "MyBuyTogetherModel.h"
#import "MyBuyTogetherAllViewController.h"
#import "Share.h"
#import "AddJobViewController.h"
#import "CompanyIntroViewController.h"
#import "MyJobManagementViewController.h"
#import "DeliveryBoxViewController.h"
#import "InterviewManagementViewController.h"
#import "ShopHomeViewController.h"

#import "AlertSignView.h"

#import "UIBarButtonItem+Badge.h"
#import "UIButton+Badge.h"
#import "privateChat.h"
#import "WKWebViewController.h"
#import "WaitForInterviewViewController.h"
#import "JobCollectionViewController.h"
#import "CertifySelectViewController.h"
#import <AXWebViewController.h>
#import "EditShopInfoViewController.h"
#import <Masonry.h>

@interface PerCenterViewController () <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, MyBuyTogetherCellDelegate>

@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UITableView *buyTogetherTableView;
@property (strong ,nonatomic) NSMutableArray *buyTogetherInfoArr;
@property CGFloat scrollContentSizeY;
@property NSInteger page;
@property (strong ,nonatomic) NSArray *vcArr1;

//以下两个变量是拿来每次进入个人中心时判断角色有没发生变化如果有的话则刷新UI
@property (assign, nonatomic) NSInteger lastRole;
@property (assign, nonatomic) NSInteger nowRole;

@property (assign, nonatomic) BOOL shouldShowPindan;

@property (strong, nonatomic) NSString *customerServiceNum;

@end

@implementation PerCenterViewController {
    UIButton        *_noticeBtn;
    UIImageView *_headPic;
    UIImageView *_levelPic;
	UILabel     *_basicUserName;	//企业角色同时显示个人昵称
    UILabel     *_userName;
    UILabel     *_title;
    UILabel     *_desc;
    UIImageView *_gender;
    UILabel     *_deposit;
    
    UILabel     *_uId;
    UILabel     *_perHome;
    UIImageView *_arrowImg;
    UIButton    *_shoppingCar;
    UIButton    *_phoneBind;
    UILabel     *_perInfo;
    UIButton    *_perHomePageBtn;
    
    UITableView *_tableView;
    PerTableViewCell    *_cell;
    
    NSDictionary    *_userInfo;
    NSArray         *_lineInfoArr;
    NSArray         *_lineImgArr;
    NSArray         *_vcArr;
    
    UILabel         *_realState; // 实名认证状态
    
    UILabel         *dayEarnNum;
    UILabel         *inviteCount;
    UILabel         *interviewSuccessNum;
    UIButton        *waitOrderBtn;
    
    UIImageView     *shopHeadImg;
    UILabel         *shopTitle;
    UILabel         *shopDesc;
    
}


- (void)c2cNotification:(NSNotification *)notification {
    NSLog(@"--接收到私聊提醒通知--\n%@", notification.userInfo);
    [self updateNum];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"c2cNotification" object:nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
	[self updateUserInfo];
    NSLog(@"Viewwillappear被调用了");
	NSInteger role = [GetUserDefaule(USERINFO)[@"role"] integerValue];
	if (role != 0) {
		[self updateNum];
	}
	[self getBuyTogetherList];
}
- (void)viewWillDisappear:(BOOL)animated
{
	[self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	self.page = 1;
    _userInfo = GetUserDefaule(USERINFO);
	NSInteger role = [GetUserDefaule(USERINFO)[@"role"] integerValue];
	self.lastRole = role;
	self.nowRole = role;
    NSLog(@"ViewDidload被调用了");
    NSLog(@"userInfo = %@", _userInfo);
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(c2cNotification:)name:@"c2cNotification" object:nil];
	
    [self createUI];
    
    [self refreshData];
	[self getCustomerServiceNum];
}

- (void)assignment {
    
    [_headPic sd_setImageWithURL:[NSURL URLWithString:_userInfo[@"face"]] placeholderImage:[UIImage imageNamed:@"placeHolder.png"]];
	
    _userName.text = _userInfo[@"nickname"];
    CGSize userNameSize = [LZCTools textSizeWithText:_userName.text font:_userName.font];
    
    _userName.frame = CGRectMake(10+_headPic.x+_headPic.width, _headPic.centerY-2-userNameSize.height, userNameSize.width, userNameSize.height);
    _gender.frame = CGRectMake(_userName.x+_userName.width+5, _userName.y, userNameSize.height-4, userNameSize.height-4);
    _uId.frame = CGRectMake(_userName.x, _headPic.centerY, SW(2), _headPic.height/2);
    _uId.text = [NSString stringWithFormat:@"ID:%@", _userInfo[@"user_id"]];
    
    if ([_userInfo[@"sex"] isEqualToString:@"1"]) {
        _gender.image = [UIImage imageNamed:@"sex_boy"];
    }
    else
        _gender.image = [UIImage imageNamed:@"sex_girl"];
    
    UILabel *postsV = [self.view viewWithTag:21];
    UILabel *focusV = [self.view viewWithTag:22];
    UILabel *fansV = [self.view viewWithTag:23];
    
    postsV.text = _userInfo[@"posts_count"];
    focusV.text = _userInfo[@"following_count"];
    fansV.text = _userInfo[@"followers_count"];
    
}

- (void)updateNum {
    
    [[NetworkTool sharedTool] requestWithName:@"未读消息" URLString:APIUnreadTips parameters:nil method:@"GET" callBack:^(id responseObject) {
        
        int a = [responseObject[@"data"][@"notification"] intValue];
        int b = [responseObject[@"data"][@"message"] intValue];
        
        int count = [privateChat chatListUnReadMessageNum];
		
		_noticeBtn.shouldHideBadgeAtZero = YES;
        _noticeBtn.badgeValue = [NSString stringWithFormat:@"%d", a+b+count];
    }];
}

#pragma mark ==========构建UI==========
- (void)createUI
{
    self.view.backgroundColor = UISeparatedColorRGB;

	UIView *fakeStatusBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Height_StatusBar)];
	fakeStatusBar.backgroundColor = UIMainColorRGB;
	[self.view addSubview:fakeStatusBar];
	
	_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, fakeStatusBar.height, SCREEN_WIDTH, SCREEN_HEIGHT)];
	_scrollView.backgroundColor = UISeparatedColorRGB;
	[self.view addSubview:_scrollView];
	
	UIView *headBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115)];
	[self.scrollView addSubview:headBgView];
	headBgView.backgroundColor = UIMainColorRGB;
	
	UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	[settingBtn setBackgroundImage:IMAGE(@"per_set") forState:UIControlStateNormal];
	settingBtn.frame = CGRectMake(30, 10, 20, 20);
	[headBgView addSubview:settingBtn];
	[settingBtn addTarget:self action:@selector(settingClick:)];
	
	_noticeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	[_noticeBtn setImage:IMAGE(@"zhibo_notice") forState:UIControlStateNormal];
	_noticeBtn.frame = CGRectMake(SCREEN_WIDTH-60, 5, 44, 30);
	[headBgView addSubview:_noticeBtn];
	[_noticeBtn addTarget:self action:@selector(perLettersClick:)];
	_noticeBtn.badgeBGColor = kRedColor;
	
	UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(SW(2)-100/2, settingBtn.y, 100, 20)];
	titleLabel.text = @"个人中心";
	titleLabel.textColor = kWhiteColor;
	titleLabel.textAlignment = NSTextAlignmentCenter;
	
	[headBgView addSubview:titleLabel];
	
    UIView *userInfoView = [[UIView alloc] initWithFrame:CGRectMake(10, headBgView.height-55, SCREEN_WIDTH-20, 100)];
    userInfoView.layer.cornerRadius = 13;
    userInfoView.backgroundColor = kWhiteColor;
    [self.scrollView addSubview:userInfoView];
    _headPic = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SW(6), SW(6))];
    _headPic.layer.cornerRadius = _headPic.width/2;
    _headPic.layer.masksToBounds = YES;
    _headPic.contentMode = UIViewContentModeScaleAspectFill;
    _headPic.clipsToBounds = YES;
    [userInfoView addSubview:_headPic];
	
	_basicUserName = [[UILabel alloc] initWithFrame:CGRectMake(_headPic.x+_headPic.width+10, _headPic.y, SW(3), 18)];
	_basicUserName.font = kUHSystemFontWithSize(14);
	NSInteger roleInt = [GetUserDefaule(USERINFO)[@"role"] integerValue];
	
    _userName = [[UILabel alloc] initWithFrame:CGRectMake(_headPic.x+_headPic.width+10, _headPic.y, SW(3), 18)];
	_userName.font = kUHSystemFontWithSize(14);
    [userInfoView addSubview:_userName];
	
	if (roleInt == 5 || roleInt == 6) {
		userInfoView.frame = CGRectMake(10, headBgView.height-55, SCREEN_WIDTH-20, 120);
		[userInfoView addSubview:_basicUserName];
		_userName.frame = CGRectMake(_basicUserName.x, _basicUserName.y+_basicUserName.height+10, _basicUserName.width, 18);
	}
    
    _desc = [[UILabel alloc] initWithFrame:CGRectMake(_userName.x, _userName.y+_userName.height+10, SW(2), 18)];
    _desc.font = kUHSystemFontWithSize(12);
	_desc.textColor = kGrayColor;
    [userInfoView addSubview:_desc];
    
    _deposit = [[UILabel alloc] initWithFrame:CGRectMake(_userName.x, _desc.y+_desc.height+10, SW(1.5), 18)];
    _deposit.text = @"面试服务费：";
    _deposit.font = kUHSystemFontWithSize(12);
	_deposit.textColor = kGrayColor;
	if(![LZCTools thinkEnv]){
		_deposit.hidden = YES;
	}
    [userInfoView addSubview:_deposit];
	
	UIButton *goToCertificateBtn = [[UIButton alloc] initWithFrame:CGRectMake(userInfoView.width-60, _deposit.y, 45, 20)];
	[goToCertificateBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
	[goToCertificateBtn setTitle:@"去认证" forState:UIControlStateNormal];
	[goToCertificateBtn setTitleColor:kRedColor forState:UIControlStateNormal];
	[goToCertificateBtn addActionWithblock:^{
		CertifySelectViewController *certifySelectVC = [[CertifySelectViewController alloc] init];
		[self.navigationController pushViewController:certifySelectVC animated:YES];
	}];
	[userInfoView addSubview:goToCertificateBtn];
	
    //分角色显示不同的userInfoView内容
	
    if (roleInt == 3 || roleInt == 4 || roleInt == 6) {
		if (roleInt == 6) {
			userInfoView.frame = CGRectMake(10, headBgView.height-60, SCREEN_WIDTH-20, 220);
		}
		else {
			userInfoView.frame = CGRectMake(10, headBgView.height-60, SCREEN_WIDTH-20, 200);
		}
		
		//分割线
		UIView *seperateLine1 = [[UIView alloc] initWithFrame:CGRectMake(20, _deposit.y+_deposit.height+10, userInfoView.width-40, 1)];
		seperateLine1.backgroundColor = UISeparatedColorRGB;
		[userInfoView addSubview:seperateLine1];
		
		shopHeadImg = [[UIImageView alloc] initWithFrame:CGRectMake(_headPic.x, _deposit.y+_deposit.height+20, SW(6), SW(6))];
		shopHeadImg.layer.cornerRadius = shopHeadImg.width/2;
		shopHeadImg.layer.masksToBounds = YES;
		shopHeadImg.contentMode = UIViewContentModeScaleAspectFill;
		shopHeadImg.clipsToBounds = YES;
		[userInfoView addSubview:shopHeadImg];
		shopTitle = [[UILabel alloc] initWithFrame:CGRectMake(shopHeadImg.x+shopHeadImg.width+10, shopHeadImg.y+10, SW(3), 18)];
		[userInfoView addSubview:shopTitle];
		shopDesc = [[UILabel alloc] initWithFrame:CGRectMake(shopTitle.x, shopHeadImg.y+shopHeadImg.height-20, SW(2), 18)];
		shopDesc.font = kUHSystemFontWithSize(12);
		shopDesc.textColor = kGrayColor;
		[userInfoView addSubview:shopDesc];
		goToCertificateBtn.frame = CGRectMake(userInfoView.width-60, shopDesc.y, 45, 20);
		UIButton *editShopInfo = [[UIButton alloc] initWithFrame:CGRectMake(userInfoView.width-30, shopTitle.y, 18, 18)];
			[editShopInfo setImage:IMAGE(@"per_edit") forState:UIControlStateNormal];
			[editShopInfo addTarget:self action:@selector(editShopInfoAction:)];
			[userInfoView addSubview:editShopInfo];
    }
    else {
		
    }
	
    UIButton *editUserInfo = [[UIButton alloc] initWithFrame:CGRectMake(userInfoView.width-30, 20, 18, 18)];
    [editUserInfo setImage:IMAGE(@"per_edit") forState:UIControlStateNormal];
    [editUserInfo addTarget:self action:@selector(editAction:)];
    [userInfoView addSubview:editUserInfo];

    //获取个人信息并赋值
    [self updateTopViewInfo];
    
	UIView *orderView = [[UIView alloc] initWithFrame:CGRectMake(userInfoView.x, userInfoView.y+userInfoView.height+10, SCREEN_WIDTH-20, SH(5))];
	orderView.backgroundColor = kWhiteColor;
	orderView.layer.cornerRadius = 13;
	[self.scrollView addSubview:orderView];
	UILabel *orderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 22)];
	orderLabel.text = @"我的订单";
	UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, orderLabel.y+orderLabel.height+10, orderView.width, 1)];
	line1.backgroundColor = UISeparatedColorRGB;
	[orderView addSubview:orderLabel];
	[orderView addSubview:line1];
	
	UIButton *checkAllOrder = [UIButton buttonWithType:UIButtonTypeCustom];
	[checkAllOrder setTitle:@"查看全部订单->" forState:UIControlStateNormal];
	checkAllOrder.titleLabel.font = [UIFont systemFontOfSize:12];
	[checkAllOrder setTitleColor:kBlackColor forState:UIControlStateNormal];
	[orderView addSubview:checkAllOrder];
	[checkAllOrder mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.mas_equalTo(orderLabel);
		make.right.mas_equalTo(orderView.mas_right).offset(-10);
	}];
	[checkAllOrder addActionWithblock:^{
		MallOrderManageViewController *orderManage = [[MallOrderManageViewController alloc] init];
		[self.navigationController pushViewController:orderManage animated:YES];
	}];
	
	NSArray *orderBtnImgArr = @[@"per_order_unpaid",@"per_order_paid",@"per_order_delivered",@"per_order_finish",@"per_order_service"];
	NSArray *orderBtnTextArr = @[@"待付款",@"已付款",@"已发货",@"已完成",@"客服"];
	
	for (int i = 0; i<orderBtnImgArr.count; i++)
	{
		CGFloat btnW = (orderView.width-20-15*4)/5;		//按钮之间间距15，头尾距离两边10
		CGFloat btnX = 10+(btnW+15)*i;
		CGFloat btnY = line1.y+SW(27);
		LCButton *orderBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnW)];
		[orderBtn setTitle:orderBtnTextArr[i] forState:UIControlStateNormal];
		[orderBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        orderBtn.tag = i;
		orderBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
		[orderBtn setImage:IMAGE(orderBtnImgArr[i]) forState:UIControlStateNormal];
		[orderView addSubview:orderBtn];
        
        //先都跳转到原来写好的订单管理页面，后续再用tag区分来改
		if (i != orderBtnImgArr.count-1) {
			[orderBtn addTarget:self action:@selector(myOrderClick:) forControlEvents:UIControlEventTouchUpInside];
		}
		else {
			[orderBtn addActionWithblock:^{
				NSMutableString *tstr=[[NSMutableString alloc] initWithFormat:@"tel:%@", self.customerServiceNum];
				NSLog(@"手机号======%@",tstr);
				[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tstr] options:@{} completionHandler:nil];
			}];
		}
	}
	
	//我的拼单
	UIView *pindan = [[UIView alloc] initWithFrame:CGRectMake(orderView.x, orderView.y+orderView.height+10, orderView.width, SH(4))];
	pindan.backgroundColor = kWhiteColor;
	pindan.layer.cornerRadius = 13;
	[self.scrollView addSubview:pindan];
	UILabel *pindanLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 22)];
	pindanLabel.text = @"我的拼单";
	UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, pindanLabel.y+pindanLabel.height+10, pindan.width, 1)];
	line2.backgroundColor = UISeparatedColorRGB;
	[pindan addSubview:pindanLabel];
	[pindan addSubview:line2];
	_buyTogetherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, line2.y+5, pindan.width, 120) style:UITableViewStylePlain];
	[_buyTogetherTableView registerNib:[UINib nibWithNibName:@"MyBuyTogetherTableViewCell" bundle:nil] forCellReuseIdentifier:@"buyTogetherCell"];
	_buyTogetherTableView.dataSource = self;
	_buyTogetherTableView.delegate = self;
	_buyTogetherTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
	[pindan addSubview:_buyTogetherTableView];
	
	UIButton *checkAllBtn = [[UIButton alloc] initWithFrame:CGRectMake(pindan.width-110, 5, 100, 30)];
	[checkAllBtn setTitle:@"查看全部订单 >" forState:UIControlStateNormal];
	[checkAllBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
	[checkAllBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
	[checkAllBtn addTarget:self action:@selector(myBuyTogetherAll:) forControlEvents:UIControlEventTouchUpInside];
	[pindan addSubview:checkAllBtn];
	
	UIView *myButtonView = [[UIView alloc] initWithFrame:CGRectMake(pindan.x, pindan.y+pindan.height+10, pindan.width, SH(3))];
	if (self.buyTogetherInfoArr.count < 1) {
		myButtonView.frame = CGRectMake(orderView.x, orderView.y+orderView.height+10, orderView.width, SH(3));
		[pindan removeFromSuperview];
	}
	myButtonView.backgroundColor = kWhiteColor;
	myButtonView.layer.cornerRadius = 13;
	[self.scrollView addSubview:myButtonView];
	NSArray *myBtnImgArr = nil;
	NSArray *myBtnTextArr = nil;
	
	//点击按钮会跳转的控制器们
	
	UIViewController *vcN = [[UIViewController alloc] init];//拿来凑数的
    vcN.view.backgroundColor = UISeparatedColorRGB;
    
	//购物车
    MKJShoppingCartViewController *shopCar = [[MKJShoppingCartViewController alloc] init];
    
	//钱包
	PerWalletNewViewController *walletVC = [[PerWalletNewViewController alloc] init];
    NSLog(@"the user info when reach here is :%@", _userInfo);
    
    //我的收藏
    MallCollectViewController *collect = [[MallCollectViewController alloc] init];
    
    //地址管理
    MallAddressViewController *mallAddress = [[MallAddressViewController alloc] init];
    
	//积分？暂时不用
	PerWalletRecordViewController *recordVC = [[PerWalletRecordViewController alloc] init];
	recordVC.type = 3;
	recordVC.totalScore = [_userInfo valueForKey:@"score"];
	
    //关注
    PerFocusAFansViewController *follow = [[PerFocusAFansViewController alloc] init];
    follow.vcType = 1;
    NSLog(@"the user info when reach here is :%@", _userInfo);
    follow.userInfo = _userInfo;
    
    //粉丝
    PerFocusAFansViewController *fans = [[PerFocusAFansViewController alloc] init];
    fans.vcType = 0;
    fans.userInfo = _userInfo;
    
	//粉丝贡献
	FansRankViewController *rankVC = [[FansRankViewController alloc] init];
	rankVC.userId = GetUserDefaule(USERINFO)[@"user_id"];
	
	MyResumeManageViewController *resumeManageVC = [[MyResumeManageViewController alloc] init];
	
	DeliveryBoxViewController *deliveryVC = [[DeliveryBoxViewController alloc] init];
	
	InterviewManagementViewController *interviewManageVC = [[InterviewManagementViewController alloc] init];
	
	WaitForInterviewViewController *replayInterviewVC = [[WaitForInterviewViewController alloc] init];
	replayInterviewVC.mode = 1;
	
	JobCollectionViewController *jobCollection = [[JobCollectionViewController alloc] init];
	
	NSLog(@"the role in perview is %ld", [GetUserDefaule(USERINFO)[@"role"] integerValue]);
	
	if ([LZCTools thinkEnv]) {
		switch ([GetUserDefaule(USERINFO)[@"role"] integerValue]) {
			case 1:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_concern"];
				
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6)*2);
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, follow];
				
				break;
			case 2:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_my_resume",@"com_list_interview",@"com_list_invitation",@"per_job_collect",@"per_concern",@"per_video_history"];
				
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"我的简历",@"投递箱",@"面试管理",@"岗位收藏",@"关注",@"视频回放"];
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, resumeManageVC, deliveryVC, interviewManageVC, jobCollection, follow, replayInterviewVC];
				
				break;
			case 3:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_concern",@"per_fans",@"per_list_ranking"];
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"关注",@"粉丝",@"粉丝贡献"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6));
				
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, follow, fans, rankVC];
				break;
			case 4:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_my_resume",@"com_list_interview",@"com_list_invitation",@"per_job_collect",@"per_concern",@"per_fans",@"per_list_ranking",@"per_video_history"];
				
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"我的简历",@"投递岗位",@"面试管理",@"岗位收藏",@"关注",@"粉丝",@"粉丝贡献",@"视频回放"];
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, resumeManageVC, deliveryVC, interviewManageVC, jobCollection, follow, fans, rankVC, replayInterviewVC];
				break;
			case 5:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_concern",@"per_video_history"];
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"关注",@"视频回放"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6));
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, follow, replayInterviewVC];
				break;
			case 6:
				myBtnImgArr = @[@"per_wallet",@"per_cart",@"per_address",@"per_shop_collect",@"per_concern",@"per_fans",@"per_list_ranking",@"per_video_history",];
				myBtnTextArr = @[@"我的钱包",@"购物车",@"地址管理",@"商品收藏",@"关注",@"粉丝",@"粉丝贡献",@"视频回放"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6));
				
				_vcArr1 = @[walletVC, shopCar, mallAddress, collect, follow, fans, rankVC, replayInterviewVC];
				break;
			default:
				break;
		}
	}
	else {
		switch ([GetUserDefaule(USERINFO)[@"role"] integerValue]) {
			case 1:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_concern"];
				
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"关注"];
				_vcArr1 = @[shopCar, mallAddress, collect, follow];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6)*2);
				break;
			case 2:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_my_resume",@"com_list_interview",@"com_list_invitation",@"per_job_collect",@"per_concern"];
				
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"我的简历",@"投递箱",@"面试管理",@"岗位收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6));
				_vcArr1 = @[shopCar, mallAddress, collect, resumeManageVC, deliveryVC, interviewManageVC, jobCollection, follow];
				
				break;
			case 3:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_concern"];
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6)*2);
				
				_vcArr1 = @[shopCar, mallAddress, collect, follow];
				break;
			case 4:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_my_resume",@"com_list_interview",@"com_list_invitation",@"per_job_collect",@"per_concern"];
				
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"我的简历",@"投递岗位",@"面试管理",@"岗位收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6));
				_vcArr1 = @[shopCar, mallAddress, collect, resumeManageVC, deliveryVC, interviewManageVC, jobCollection, follow];
				break;
			case 5:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_concern"];
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6)*2);
				_vcArr1 = @[shopCar, mallAddress, collect, follow];
				break;
			case 6:
				myBtnImgArr = @[@"per_cart",@"per_address",@"per_shop_collect",@"per_concern"];
				myBtnTextArr = @[@"购物车",@"地址管理",@"商品收藏",@"关注"];
				myButtonView.frame = CGRectMake(myButtonView.x, myButtonView.y, myButtonView.width, myButtonView.height-SW(6)*2);
				
				_vcArr1 = @[shopCar, mallAddress, collect, follow];
				break;
			default:
				break;
		}
	}
	
	
	for (int i = 0; i<myBtnImgArr.count; i++)
	{
		CGFloat btnW = (myButtonView.width-15*2-45*3)/4;		//按钮之间间距45，头尾距离两边15
		CGFloat btnX = 15+(btnW+45)*(i%4);
		CGFloat btnY = SW(27)+(i/4)*SW(5.5);
		LCButton *myBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnW)];
		[myBtn setTitle:myBtnTextArr[i] forState:UIControlStateNormal];
		[myBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
		[myBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
		myBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
		[myBtn setImage:IMAGE(myBtnImgArr[i]) forState:UIControlStateNormal];
        myBtn.tag = 11+i;
        [myBtn addTarget:self action:@selector(myBtnClick:) forControlEvents:UIControlEventTouchUpInside];
		[myButtonView addSubview:myBtn];
	}
	
	NSInteger role = [GetUserDefaule(USERINFO)[@"role"] integerValue];
	if (role == 1 || role == 2) {
		self.scrollContentSizeY = SCREEN_HEIGHT+20;
	}
	else if (role == 3 || role == 4 || role == 6) {
		UIView *mallManagement = [[UIView alloc] initWithFrame:CGRectMake(myButtonView.x, myButtonView.y+myButtonView.height+10, myButtonView.width, SH(3))];
		mallManagement.backgroundColor = kWhiteColor;
		mallManagement.layer.cornerRadius = 13;
		[self.scrollView addSubview:mallManagement];
		UILabel *mallLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 22)];
		mallLabel.text = @"商城管理";
		UIView *line3 = [[UIView alloc] initWithFrame:CGRectMake(0, mallLabel.y+mallLabel.height+10, mallManagement.width, 1)];
		line3.backgroundColor = UISeparatedColorRGB;
		[mallManagement addSubview:mallLabel];
		[mallManagement addSubview:line3];
		dayEarnNum = [[UILabel alloc] initWithFrame:CGRectMake(15, line3.y+SH(40), SW(2.8), SW(18))];
		dayEarnNum.text = @"0.0元";
		dayEarnNum.textColor = kRedColor;
        dayEarnNum.textAlignment = NSTextAlignmentCenter;
		[mallManagement addSubview:dayEarnNum];
		UILabel *dayEarnText = [[UILabel alloc] initWithFrame:CGRectMake(SW(8), dayEarnNum.y+dayEarnNum.height+SH(40), SW(5), SW(18))];
		dayEarnText.text = @"当天收入";
		dayEarnText.textColor = kBlackColor;
		[mallManagement addSubview:dayEarnText];
		
		waitOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        waitOrderBtn.badgeBGColor = kRedColor;
		waitOrderBtn.frame = CGRectMake(mallManagement.width/2+SW(5), line3.y+SH(40), SW(15), SW(15));
		[waitOrderBtn setBackgroundImage:IMAGE(@"shop_goods_paid") forState:UIControlStateNormal];
		[waitOrderBtn addTarget:self action:@selector(orderWaitForDeliver:) forControlEvents:UIControlEventTouchUpInside];
		[mallManagement addSubview:waitOrderBtn];
		UILabel *waitOrderText = [[UILabel alloc] initWithFrame:CGRectMake(mallManagement.width/2+SW(8), dayEarnText.y, SW(4), SW(18))];
		waitOrderText.text = @"待发货订单";
		[mallManagement addSubview:waitOrderText];
		NSArray *mallBtnImg = @[@"shop_goods_upload",@"shop_list_goods",@"shop_list_order",@"shop_data_count"];
		NSArray *mallBtnText = @[@"商品发布",@"商品管理",@"平台订单",@"数据统计"];
		for (int i = 0; i<mallBtnImg.count; i++)
		{
			CGFloat btnW = (myButtonView.width-15*2-45*3)/4;		//按钮之间间距45，头尾距离两边15
			CGFloat btnX = 15+(btnW+45)*(i%4);
			CGFloat btnY = dayEarnText.y+dayEarnText.height+SH(26)+(i/4)*SW(5.5);
			LCButton *myBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnW)];
			[myBtn setTitle:mallBtnText[i] forState:UIControlStateNormal];
			[myBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
			[myBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
			myBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
			[myBtn setImage:IMAGE(mallBtnImg[i]) forState:UIControlStateNormal];
			myBtn.tag = 31+i;
			[myBtn addTarget:self action:@selector(mallBtnClick:) forControlEvents:UIControlEventTouchUpInside];
			[mallManagement addSubview:myBtn];
		}
		if (role == 3 || role == 4) {
			self.scrollContentSizeY = mallManagement.y+mallManagement.height+SH(9);
		}
		else {
			UIView *recruitManagement = [[UIView alloc] initWithFrame:CGRectMake(mallManagement.x, mallManagement.y+mallManagement.height+10, mallManagement.width, SH(2.3))];
			recruitManagement.backgroundColor = kWhiteColor;
			recruitManagement.layer.cornerRadius = 13;
			[self.scrollView addSubview:recruitManagement];
			UILabel *recruitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 22)];
			recruitLabel.text = @"招聘管理";
			UIView *line4 = [[UIView alloc] initWithFrame:CGRectMake(0, recruitLabel.y+recruitLabel.height+10, myButtonView.width, 1)];
			line4.backgroundColor = UISeparatedColorRGB;
			[recruitManagement addSubview:recruitLabel];
			[recruitManagement addSubview:line4];
			inviteCount = [[UILabel alloc] initWithFrame:CGRectMake(SW(6), line4.y+SH(40), SW(4), SW(18))];
			inviteCount.text = @"1个";
            inviteCount.textAlignment = NSTextAlignmentLeft;
			inviteCount.textColor = kRedColor;
			[recruitManagement addSubview:inviteCount];
			UILabel *inviteText = [[UILabel alloc] initWithFrame:CGRectMake(inviteCount.x-SW(10), inviteCount.y+inviteCount.height+SH(40), SW(3), SW(18))];
			inviteText.text = @"本月邀约面试";
			inviteText.adjustsFontSizeToFitWidth = YES;
			inviteText.textColor = kBlackColor;
			[recruitManagement addSubview:inviteText];
			
			interviewSuccessNum = [[UILabel alloc] initWithFrame:CGRectMake(recruitManagement.width/2+SW(5), line4.y+SH(40), SW(4), SW(15))];
			interviewSuccessNum.text = @"1个";
            interviewSuccessNum.textAlignment = NSTextAlignmentLeft;
			interviewSuccessNum.textColor = kRedColor;
			[recruitManagement addSubview:interviewSuccessNum];
			UILabel *interviewSuccess = [[UILabel alloc] initWithFrame:CGRectMake(recruitManagement.width/2+SW(15), inviteText.y, SW(3), SW(18))];
			interviewSuccess.text = @"本月面试成功记录";
			interviewSuccess.adjustsFontSizeToFitWidth = YES;
			[recruitManagement addSubview:interviewSuccess];
			NSArray *recruitBtnImg = @[@"com_job_release",@"com_list_job",@"com_intro",@"com_applicant_collect",@"com_list_interview",@"com_list_invitation"];
			NSArray *recruitText = @[@"发布岗位",@"岗位管理",@"公司介绍",@"人才收藏",@"投递箱",@"面试管理"];
			for (int i = 0; i<recruitBtnImg.count; i++)
			{
				CGFloat btnW = (myButtonView.width-15*2-45*3)/4;		//按钮之间间距45，头尾距离两边15
				CGFloat btnX = 15+(btnW+45)*(i%4);
				CGFloat btnY = inviteText.y+inviteText.height+SH(26)+(i/4)*SW(5.5);
				LCButton *myBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnW)];
				[myBtn setTitle:recruitText[i] forState:UIControlStateNormal];
				[myBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
				[myBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
				myBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
				myBtn.tag = 41+i;
				[myBtn setImage:IMAGE(recruitBtnImg[i]) forState:UIControlStateNormal];
				[recruitManagement addSubview:myBtn];
				[myBtn addTarget:self action:@selector(companyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
			}
			self.scrollContentSizeY = recruitManagement.y+recruitManagement.height+SH(9);
		}
		
	}
	else if(role == 5){
		UIView *recruitManagement = [[UIView alloc] initWithFrame:CGRectMake(myButtonView.x, myButtonView.y+myButtonView.height+10, myButtonView.width, SH(2.3))];
		recruitManagement.backgroundColor = kWhiteColor;
		recruitManagement.layer.cornerRadius = 13;
		[self.scrollView addSubview:recruitManagement];
		UILabel *recruitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 22)];
		recruitLabel.text = @"招聘管理";
		UIView *line4 = [[UIView alloc] initWithFrame:CGRectMake(0, recruitLabel.y+recruitLabel.height+10, myButtonView.width, 1)];
		line4.backgroundColor = UISeparatedColorRGB;
		[recruitManagement addSubview:recruitLabel];
		[recruitManagement addSubview:line4];
		inviteCount = [[UILabel alloc] initWithFrame:CGRectMake(SW(6), line4.y+SH(40), SW(4), SW(18))];
		inviteCount.text = @"1个";
        inviteCount.textAlignment = NSTextAlignmentLeft;
		inviteCount.textColor = kRedColor;
		[recruitManagement addSubview:inviteCount];
		UILabel *inviteText = [[UILabel alloc] initWithFrame:CGRectMake(inviteCount.x-SW(10), inviteCount.y+inviteCount.height+SH(40), SW(3), SW(18))];
		inviteText.text = @"本月邀约面试";
		inviteText.adjustsFontSizeToFitWidth = YES;
		inviteText.textColor = kBlackColor;
		[recruitManagement addSubview:inviteText];
		
		interviewSuccessNum = [[UILabel alloc] initWithFrame:CGRectMake(recruitManagement.width/2+SW(5), line4.y+SH(40), SW(4), SW(15))];
		interviewSuccessNum.text = @"1个";
        interviewSuccessNum.textAlignment = NSTextAlignmentLeft;
		interviewSuccessNum.textColor = kRedColor;
		[recruitManagement addSubview:interviewSuccessNum];
		UILabel *interviewSuccess = [[UILabel alloc] initWithFrame:CGRectMake(recruitManagement.width/2+SW(15), inviteText.y, SW(3), SW(18))];
		interviewSuccess.text = @"本月面试成功记录";
		interviewSuccess.adjustsFontSizeToFitWidth = YES;
		[recruitManagement addSubview:interviewSuccess];
		NSArray *recruitBtnImg = @[@"com_job_release",@"com_list_job",@"com_intro",@"com_applicant_collect",@"com_list_interview",@"com_list_invitation"];
		NSArray *recruitText = @[@"发布岗位",@"岗位管理",@"公司介绍",@"人才收藏",@"投递箱",@"面试管理"];
		for (int i = 0; i<recruitBtnImg.count; i++)
		{
			CGFloat btnW = (myButtonView.width-15*2-45*3)/4;		//按钮之间间距45，头尾距离两边15
			CGFloat btnX = 15+(btnW+45)*(i%4);
			CGFloat btnY = inviteText.y+inviteText.height+SH(26)+(i/4)*SW(5.5);
			LCButton *myBtn = [[LCButton alloc] initWithFrame:CGRectMake(btnX, btnY, btnW, btnW)];
			[myBtn setTitle:recruitText[i] forState:UIControlStateNormal];
			[myBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
			[myBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
			myBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
			[myBtn setImage:IMAGE(recruitBtnImg[i]) forState:UIControlStateNormal];
			myBtn.tag = 41+i;
			[myBtn addTarget:self action:@selector(companyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
			[recruitManagement addSubview:myBtn];
		}
		self.scrollContentSizeY = recruitManagement.y+recruitManagement.height+SH(9);
	}
	
	self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, self.scrollContentSizeY);
    
}

- (void)pushPerHome {
	
    
}

#pragma mark ==========更新数据==========
- (void)refreshData {
    
    __weak typeof (self) weakSelf = self;
    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        NSLog(@"下拉刷新");
        [weakSelf updateUserInfo];
    }];
    
}

#pragma mark ==========UITableView==========
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
	MyBuyTogetherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buyTogetherCell"];
	MyBuyTogetherModel *model = self.buyTogetherInfoArr[indexPath.row];
	cell.model = model;
	cell.delegate = self;
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
	return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.buyTogetherInfoArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 120;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
	
}

#pragma mark ==========响应方法==========

/**
 更新用户信息
 */
- (void)updateUserInfo {
	
    [[NetworkTool sharedTool] requestWithName:@"获取用户信息" URLString:APIUser parameters:nil method:@"GET" callBack:^(id responseObject) {
        NSDictionary *userDict = [responseObject valueForKey:@"data"];
        SetUserDefaule(userDict, USERINFO);
		NSLog(@"user info in per is %@", userDict);
		NSInteger role = [GetUserDefaule(USERINFO)[@"role"] integerValue];
		if (role == 0) {
			[self presentViewController:[LZCTools alertMessage:@"请先登录"]animated:YES completion:nil];
			return;
		}
		self.lastRole = self.nowRole;
		self.nowRole = role;
		_userInfo = userDict;
		if (self.lastRole != self.nowRole) {
			[self.view removeAllSubViews];
			[self createUI];
		}
		[self updateTopViewInfo];
    }];
}

/**
 点击编辑按钮
 */
- (void)editAction:(id)sender {
    NSLog(@"点击了编辑按钮");
    
    PerInfoEditViewController *editVC = [[PerInfoEditViewController alloc] init];
    editVC.userInfo = _userInfo;
    [self pushAction:editVC];
}

- (void)editShopInfoAction:(id)sender {
	NSLog(@"点击了编辑商家信息按钮");
	
	EditShopInfoViewController *editVC = [[EditShopInfoViewController alloc] init];
	[self pushAction:editVC];
}

/**
 动态、粉丝、关注点击
 */
- (void)btnsClick:(UIView *)sender {
    
    UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
    
    NSString *index = [NSString stringWithFormat:@"%ld", [tapRecognizer.view tag]];
    
    if ([index isEqualToString:@"11"]) {
        NSLog(@"点击动态");
        [self pushPerHome];
    }
    else if ([index isEqualToString:@"12"]) {
        NSLog(@"点击关注");
        PerFocusAFansViewController *FFVC = [[PerFocusAFansViewController alloc] init];
        FFVC.vcType = 1;
        FFVC.userInfo = _userInfo;
        [self.navigationController pushViewController:FFVC animated:YES];
    }
    else {
        NSLog(@"点击粉丝");
        PerFocusAFansViewController *FFVC = [[PerFocusAFansViewController alloc] init];
        FFVC.vcType = 0;
        FFVC.userInfo = _userInfo;
        [self.navigationController pushViewController:FFVC animated:YES];
    }
}

- (void)perLettersClick:(id)sender {
//    [self.navigationController pushViewController:[[MessageViewController alloc] init] animated:YES];
    if (GetUserDefaule(USERINFO) == NULL) {
//        [self presentViewController:[LZCTools alertMessage:@"请先登录"]animated:YES completion:nil];
        return;
    }
    else {
        [self.navigationController pushViewController:[[ConversationListViewController alloc] init] animated:YES];
    }
}

- (void)pushAction:(UIViewController *)VC {
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)headBtnClick:(UIButton *)sender {
    if (sender.tag == 555) {

    }
    else {
        BindingPhoneViewController *phoneVC = [[BindingPhoneViewController alloc] init];
        phoneVC.phone = _userInfo[@"mobile"];
        [self.navigationController pushViewController:phoneVC animated:YES];
    }
}

- (void)settingClick:(id)sender
{
    [self.navigationController pushViewController:[[PerSettingViewController alloc] init] animated:YES];
}

- (void)mallBtnClick:(UIButton *)sender
{
    //WKWebViewController *mallH5VC = [[WKWebViewController alloc] init];
	NSString *urlStr;
    switch (sender.tag) {
        case 31:
            urlStr = [NSString stringWithFormat:@"%@/mobile/goods/create/token/%@", APIBackEndUrl, [GetUserDefaule(Token) valueForKey:@"access_token"]];
            break;
        case 32:
            urlStr = [NSString stringWithFormat:@"%@/mobile/goods/goods/token/%@", APIBackEndUrl, [GetUserDefaule(Token) valueForKey:@"access_token"]];
            break;
        case 33:
            urlStr = [NSString stringWithFormat:@"%@/mobile/order/index/token/%@", APIBackEndUrl, [GetUserDefaule(Token) valueForKey:@"access_token"]];
            break;
        case 34:
            urlStr = [NSString stringWithFormat:@"%@/mobile/order/statistics/token/%@", APIBackEndUrl, [GetUserDefaule(Token) valueForKey:@"access_token"]];
            break;
            
        default:
            break;
    }
	/*
	[mallH5VC loadWebURLSring:urlStr];
	mallH5VC.shouldShowCancelBtn = YES;
	[self presentViewController:mallH5VC animated:YES completion:nil];
	 */
	AXWebViewController *webViewVC = [[AXWebViewController alloc] initWithAddress:urlStr];
	webViewVC.showsToolBar = NO;
	webViewVC.navigationController.navigationBar.translucent = NO;
	webViewVC.navigationType = AXWebViewControllerNavigationBarItem;
	[self.navigationController pushViewController:webViewVC animated:YES];
}

- (void)myOrderClick:(UIButton *)sender
{
    MallOrderManageViewController *orderManage = [[MallOrderManageViewController alloc] init];
    orderManage.defaultIndex = sender.tag;
    [self.navigationController pushViewController:orderManage animated:YES];
}

- (void)myBtnClick:(UIButton *)sender
{
    [self.navigationController pushViewController:self.vcArr1[sender.tag-11] animated:YES];
}

- (void)companyBtnClick:(UIButton *)sender
{
	if (sender.tag == 41) {
		AddJobViewController *vc = [[AddJobViewController alloc] init];
		[self presentViewController:vc animated:YES completion:nil];
	}
	if (sender.tag == 42) {
		MyJobManagementViewController *vc = [[MyJobManagementViewController alloc] init];
		[self.navigationController pushViewController:vc animated:YES];
	}
	if (sender.tag == 43) {
		CompanyIntroViewController *vc = [[CompanyIntroViewController alloc] init];
		[self.navigationController pushViewController:vc animated:YES];
	}
	if (sender.tag == 44) {
		JobCollectionViewController *vc = [[JobCollectionViewController alloc] init];
		[self.navigationController pushViewController:vc animated:YES];
	}
	if (sender.tag == 45) {
		DeliveryBoxViewController *vc = [[DeliveryBoxViewController alloc] init];
		[self.navigationController pushViewController:vc animated:YES];
	}
	if (sender.tag == 46) {
		InterviewManagementViewController *vc = [[InterviewManagementViewController alloc] init];
		[self.navigationController pushViewController:vc animated:YES];
	}
}

- (void)myBuyTogetherAll:(UIButton *)sender
{
	MyBuyTogetherAllViewController *vc = [[MyBuyTogetherAllViewController alloc] init];
	[self.navigationController pushViewController:vc animated:YES];
}

- (void)orderWaitForDeliver:(UIButton *)sender
{
	NSString *urlStr = [NSString stringWithFormat:@"%@/mobile/order/order/token/%@", APIBackEndUrl, [GetUserDefaule(Token) valueForKey:@"access_token"]];
    AXWebViewController *webViewVC = [[AXWebViewController alloc] initWithAddress:urlStr];
    webViewVC.showsToolBar = NO;
    webViewVC.navigationController.navigationBar.translucent = NO;
    webViewVC.navigationType = AXWebViewControllerNavigationBarItem;
    [self.navigationController pushViewController:webViewVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)updateTopViewInfo
{
    //获取个人信息并赋值
    [[NetworkTool sharedTool] requestWithName:@"个人中心信息获取" URLString:APIPersonal parameters:nil method:@"GET" callBack:^(id responseObject) {
        NSDictionary *userDict = [responseObject valueForKey:@"data"];
        NSInteger roleNum = [GetUserDefaule(USERINFO)[@"role"] integerValue];
        if (![[userDict valueForKey:@"total_price"] isKindOfClass:[NSNull class]]) {
            dayEarnNum.text = [NSString stringWithFormat:@"%.2lf元", [userDict[@"total_price"] floatValue]];
        }
        if (![[userDict valueForKey:@"success_num"] isKindOfClass:[NSNull class]]) {
            interviewSuccessNum.text = [NSString stringWithFormat:@"%@个", userDict[@"success_num"]];
        }
        if (![[userDict valueForKey:@"interview_num"] isKindOfClass:[NSNull class]]) {
            inviteCount.text = [NSString stringWithFormat:@"%@个", userDict[@"interview_num"]];
        }
        if (![[userDict valueForKey:@"paid_num"] isKindOfClass:[NSNull class]]) {
            waitOrderBtn.badgeValue = [NSString stringWithFormat:@"%d", [userDict[@"paid_num"] intValue]];
        }

        if (![[userDict valueForKey:@"title"] isKindOfClass:[NSNull class]]) {
            _userName.text = [userDict valueForKey:@"title"];
            
            if (roleNum == 1 || roleNum == 2 || roleNum == 4) {
                NSMutableAttributedString *userNameAttri = [[NSMutableAttributedString alloc] initWithString:userDict[@"title"]];
                NSTextAttachment *sexAttch = [[NSTextAttachment alloc] init];
                if ([userDict[@"sex"] isEqualToString:@"1"]) {
                    sexAttch.image = IMAGE(@"icon_sex_boy");
                }
                else if([userDict[@"sex"] isEqualToString:@"2"])
                {
                    sexAttch.image = IMAGE(@"icon_sex_girl");
                }
                sexAttch.bounds = CGRectMake(0, -3, 15, 15);
                NSAttributedString *sexString = [NSAttributedString attributedStringWithAttachment:sexAttch];
                [userNameAttri insertAttributedString:sexString atIndex:_userName.text.length];
                _userName.attributedText = userNameAttri;
            }
            [_userName sizeToFit];
        }
        if (![[userDict valueForKey:@"desc"] isKindOfClass:[NSNull class]]) {
            _desc.text = [userDict valueForKey:@"desc"];
        }
        if (![[userDict valueForKey:@"auth_status"] isKindOfClass:[NSNull class]]) {
            _deposit.text = [userDict valueForKey:@"auth_status"];
        }

		[_headPic sd_setImageWithURL:[userDict valueForKey:@"head_img"] placeholderImage:IMAGE(@"placeHolder")];
        
        if ( roleNum == 3 || roleNum == 4 || roleNum == 6) {
            if (![[userDict valueForKey:@"shop_desc"] isKindOfClass:[NSNull class]]) {
                shopDesc.text = [userDict valueForKey:@"shop_desc"];
            }
            if (![[userDict valueForKey:@"shop_title"] isKindOfClass:[NSNull class]]) {
                shopTitle.text = [userDict valueForKey:@"shop_title"];
            }
            if (![[userDict valueForKey:@"shop_head_img"] isKindOfClass:[NSNull class]]) {
                [shopHeadImg sd_setImageWithURL:[NSURL URLWithString:[userDict valueForKey:@"shop_head_img"]] placeholderImage:IMAGE(@"placeHolder")];
            }
        }
		
		//投递箱和面试管理那两个角标
		if (roleNum == 2 || roleNum == 4) {
			UIButton *deliverBtn = [self.view viewWithTag:16];
			UIButton *interviewManagementBtn = [self.view viewWithTag:17];
			deliverBtn.badgeValue = [NSString stringWithFormat:@"%d", [userDict[@"new_delivery_num"] intValue]];
			interviewManagementBtn.badgeValue = [NSString stringWithFormat:@"%d", [userDict[@"new_interview_num"] intValue]];
		}
		else if(roleNum == 5 || roleNum == 6) {
			UIButton *deliverBtn = [self.view viewWithTag:45];
			UIButton *interviewManagementBtn = [self.view viewWithTag:46];
			deliverBtn.badgeValue = [NSString stringWithFormat:@"%d", [userDict[@"new_delivery_num"] intValue]];
			interviewManagementBtn.badgeValue = [NSString stringWithFormat:@"%d", [userDict[@"new_interview_num"] intValue]];
			_basicUserName.text = _userInfo[@"nickname"];
		}
        
    }];
}

- (void)getBuyTogetherList {
	NSDictionary *param = @{
							@"per_page":@"6",
							@"page":[NSString stringWithFormat:@"%ld", self.page],
							@"status":@"paid"
							};
	
	[[NetworkTool sharedTool] requestWithName:@"获取我的拼单列表" URLString:APIMyEcBuy parameters:param method:@"GET" callBack:^(id responseObject) {
		
		NSArray *arr = responseObject[@"data"];
		if (self.page == 1) {
			[self.buyTogetherInfoArr removeAllObjects];
		}
		for (NSDictionary *dict in arr) {
			
			MyBuyTogetherModel *model = [[MyBuyTogetherModel alloc] init];
			[model setValuesForKeysWithDictionary:dict];
			[self.buyTogetherInfoArr addObject:model];
		}
		
		//需求要通过有无拼单数据来判断“我的拼单”隐藏与否，由于一开始不会自动布局，只好低效率点刷新界面了。。
		BOOL hasPindanContent = NO;
		if (self.buyTogetherInfoArr.count > 0) {
			hasPindanContent = YES;
		}
		if (self.shouldShowPindan != hasPindanContent) {
			self.shouldShowPindan = hasPindanContent;
			[self.view removeAllSubViews];
			[self createUI];
		}
		
		[self.buyTogetherTableView reloadData];
		/*
		dispatch_async(dispatch_get_main_queue(), ^{
			[self.buyTogetherTableView reloadData];
			[self.buyTogetherTableView.mj_header endRefreshing];
			[self.buyTogetherTableView.mj_footer endRefreshing];
		});
		 */
	}];
}

- (NSMutableArray *)buyTogetherInfoArr
{
	if (!_buyTogetherInfoArr) {
		_buyTogetherInfoArr = [[NSMutableArray alloc] init];
	}
	return _buyTogetherInfoArr;
}

- (void)shareToFriend:(NSInteger)goodId :(NSString *)img :(NSString *)title
{
	NSLog(@"点击分享");
	NSString *urlStr = [NSString stringWithFormat:@"%@/mobile/download/index/goods_id/%ld", APIBackEndUrl, goodId];
	
	NSDictionary *param = @{@"text":@"我在星河汇发现一个很划算的拼单，快来看看吧",
							@"img":img,
							@"url":urlStr,
							@"title":title
							};
	[Share shareAction:param];
}

- (void)getCustomerServiceNum {
	[[NetworkTool sharedTool] requestWithName:@"获取售后电话" URLString:APIAfterSale parameters:nil method:@"GET" callBack:^(id responseObject) {
		self.customerServiceNum = responseObject[@"data"][@"mobile"];
	}];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
